$package('itsm.system');

itsm.system.extractMain=function(){
	this.opt='';
	return {
		//列表
		extractMainGrid:function(){
			var params = $.extend({},jqGridParams, {	
				url:'extract!findPager.action',
				postData:{'extractDTO.status':'待受理','extractDTO.loginName':'ALL'},
				caption:'提现管理',
				colNames:['ID','会员ID','姓名','提现金额','提现手续费','余额','银行类型','银行账户','开户地址','提现账户','处理状态','申请时间','处理时间','备注'],
			 	colModel:[
			 	          {name:'id',align:'center',width:'50px'},
			 	          {name:'loginName',align:'center',width:'80px'},
			 	          {name:'accountName',align:'center',width:'80px'},
			 	          {name:'tixiangSum',align:'center',width:'60px',formatter:function(val,data,rol){
			 	        	  return rol.tixiangSum-rol.poundage;
			 	          }},
			 	          {name:'poundage',align:'center',width:'60px'},
			 	          {name:'balance',align:'center',width:'60px'},
			 	          {name:'accountType',align:'center',width:'80px'},
			 	          {name:'bankAccount',align:'center',width:'150px'},
			 	          {name:'openBankAddress',align:'center',width:'150px'},
			 	          {name:'formAccountStr',align:'center',width:'80px'},
			 	          {name:'status',align:'center',width:'100px'},
			 	          {name:'createTime',align:'center',formatter:timeFormatter,width:'120px'},
			 	          {name:'handTime',align:'center',formatter:timeFormatter,formatter:timeFormatter,width:'120px'},
			 	          {name:'remark',align:'center',formatter:timeFormatter,width:'100px'}
			 	          
			 	],
				jsonReader: $.extend(jqGridJsonReader, {id: "id"}),
				sortname:'id',
				sortorder:'asc',
				//shrinkToFit:false,
				pager:'#extractMainPager'
				});
				$("#extractMainGrid").jqGrid(params);
				$("#extractMainGrid").navGrid('#extractMainPager',navGridParams);
				//列表操作项
				$("#t_extractMainGrid").css(jqGridTopStyles);
				$("#t_extractMainGrid").html($('#extractMainGridToolbar').html());
				
				//自适应宽度
				setGridWidth("#extractMainGrid","regCenter",10);
		},
		//打开添加窗口
		openAddWin:function(){
			opt='saveRule';
			resetForm('#extractMain_add_form');
			$('#extractMain_add_win').window('open');
		},
		
		//打开编辑窗口
		openEditWin:function(){
			opt='editRule';
			checkBeforeEditGrid('#extractMainGrid',function(rowData){
				$.post('extract!findRuleByRuleCode.action','ruleDTO.ruleCode='+rowData.ruleCode,function(data){
					$('#extractMain_ruleId').val(data.ruleId);
					$('#extractMain_ruleName').val(data.ruleName);
					$('#extractMain_ruleCode').val(data.ruleCode);
					$('#extractMain_ruleValue').val(data.ruleValue);
				});
				$('#extractMain_add_win').window('open');
			});	
		},
		
		//保存
		saveextract:function(){
			if($('#extractMain_add_win').form('validate')){
				var _param = $('#extractMain_add_win form').serialize();
				$.post('extract!'+opt+'.action',_param,function(data){
					msgShow('保存成功!','show');
					$('#extractMain_add_win').window('close');
					$('#extractMainGrid').trigger('reloadGrid');
				})
				
			}
		},
		//删除
		deleteextract:function(){
			checkBeforeDeleteGrid('#extractMainGrid',function(rowIds){
				var pp = $.param({'ids':rowIds},true);
				$.post("extract!deleteextract.action", pp, function(){
					$('#extractMainGrid').trigger('reloadGrid');
					msgShow('删除成功!','show');
				}, "json");
			});
		},
		//打开搜索窗口
		openSearchWin:function(){
			$('#extractMain_search_win').window('open');
		},
		//搜索
		searchextract:function(){
			var sdata=$('#extractMain_search_form').getForm();
			var postData = $("#extractMainGrid").jqGrid("getGridParam", "postData");
			$.extend(postData,sdata);
			var _url = 'extract!findPager.action';		
			$('#extractMainGrid').jqGrid('setGridParam',{url:_url}).trigger('reloadGrid',[{"page":"1"}]);
		},
		
		
		//打开提现处理窗口
		openExtractWin:function(opt){
			checkBeforeEditGrid('#extractMainGrid',function(rowData){
				$('#extract_id').val(rowData.id);
				if('agree'==opt){
					$('#extract_status').val('已处理');
					$('#showstatus').html('同意提现');
					$('#remark').val('已受理，将24小时内到账!');
					$('#extractMain_hanld_win').window('open');
					
				}else{
					$('#extract_status').val('拒绝');
					$('#showstatus').html('拒绝提现');
					$('#remark').val('拒绝，提现帐户信息有误!');
					$('#extractMain_hanld_win').window('open');
				}
				
			});
			
		},
		
		extractsubmit:function(){
			var _param = $('#extractMain_hanld_form').serialize();
			$.post('registerUser!userOpt.action?optType=TingXiangHand',_param,function(data){
				msgShow('处理成功!','show');
				$('#extractMain_hanld_win').window('close');
				$('#extractMainGrid').trigger('reloadGrid');
			})
		},
		
		
		init:function(){
			itsm.system.extractMain.extractMainGrid();
		}
	}
	
}();

$(function(){
	itsm.system.extractMain.init();
});